package com.example.day0830_ui_2.slice;

import com.example.day0830_ui_2.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {

    private Button button;
    private Button button1;
    private Button button2;
    private Button button3;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        button = (Button) findComponentById(ResourceTable.Id_btn_main);
        button.setClickedListener(component -> dialogSet());
    }

    private void dialogSet() {
        CommonDialog dil = new CommonDialog(getContext());

        Component layout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_ability_dialog_box, null, true);
        dil.setTransparent(true);

        dil.setContentCustomComponent(layout);
        dil.setAutoClosable(true);



        Component.ClickedListener conlisner = new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                new ToastDialog(getContext()).setText(((Button)component).getText()).show();
            }
        };
        button1 = (Button )layout.findComponentById(ResourceTable.Id_very_good);
        button2 = (Button )layout.findComponentById(ResourceTable.Id_good);
        button3 = (Button )layout.findComponentById(ResourceTable.Id_bad);
        button1.setClickedListener(conlisner);
        button2.setClickedListener(conlisner);
        button3.setClickedListener(conlisner);

        dil.show();

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
